package com.zzxz.practicaltrainingsys.mapper;

import com.zzxz.practicaltrainingsys.entity.Adm;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AdmMapper {
    //查询所有管理员信息
    @Select("SELECT * FROM adm")
    List<Adm> queryAllAdm();

    //查询具体admin_id的信息
    @Select("SELECT * FROM adm where admin_id= #{id}")
    Adm getAdmById(Integer id);

    //新增管理员信息
    @Insert("INSERT INTO adm (admin_id, admin_name, admin_sex, admin_password, admin_phone, admin_email) \n" +
            "VALUES (#{admin_id}, #{admin_name}, #{admin_sex}, #{admin_password}, #{admin_phone}, #{admin_email})")
    int insertAdm(Adm adm);

    //更新管理员信息
    @Update("UPDATE adm SET admin_name = #{admin_name}, admin_password = #{admin_password},admin_sex = #{admin_sex},\n" +
            "admin_password = #{admin_password},admin_phone = #{admin_phone}, admin_email = #{admin_email} WHERE admin_id = #{admin_id}")
    int updateAdm(Adm adm);


    //根据管理员手机号查询管理员信息
    @Select("SELECT * FROM adm WHERE admin_phone = #{phone}")
    Adm getAdmByPhone(String phone);

    //更新管理员状态
    @Update("UPDATE adm\n" +
            "SET admin_state = \n" +
            "    CASE \n" +
            "        WHEN admin_state IS NULL OR admin_state = '0' THEN '已停用'\n" +
            "        WHEN admin_state = '已停用' THEN '0'\n" +
            "        ELSE admin_state\n" +
            "    END\n" +
            "WHERE admin_id = #{admin_id};")
    int updateAdmStatus(@Param("admin_id") Integer admin_id);

}